package com.sunday.aomicaichang.ui.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.model.ResultDO;
import com.sunday.common.utils.MD5Utils;
import com.sunday.aomicaichang.R;
import com.sunday.aomicaichang.http.ApiClient;
import com.sunday.aomicaichang.model.Revenue;
import com.sunday.aomicaichang.ui.recharge.SelectRechargeActivity;
import com.sunday.member.utils.SignUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by yun_sheng on 2017/6/2.
 */

public class WalletActivity extends BaseActivity {
    @Bind(R.id.detail)
    TextView detail;
    @Bind(R.id.price)
    TextView price;
    @Bind(R.id.ly_recharge)
    RelativeLayout lyRecharge;
    @Bind(R.id.ly_set_pay)
    RelativeLayout lySetPay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_wallet);
        ButterKnife.bind(this);
        getDataNum();
    }
    @OnClick({R.id.detail,R.id.ly_recharge,R.id.ly_set_pay})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.detail:
                intent=new Intent(mContext,WalletDetailActivity.class);
                startActivity(intent);
                break;
            case R.id.ly_recharge:
                intent = new Intent(mContext, SelectRechargeActivity.class);
                startActivity(intent);
                break;
            case R.id.ly_set_pay:
                intent=new Intent(mContext,PaySetting1Activity.class);
                startActivity(intent);
                break;
        }
    }
    private void getDataNum() {
        String nonce= MD5Utils.random();
        String[] str1=new String[]{"nonce"};
        String[] str2=new String[]{nonce};
        Call<ResultDO<Revenue>> call= ApiClient.getApiAdapter().getRevenue(nonce, SignUtil.getSign(str1,str2));
        call.enqueue(new Callback<ResultDO<Revenue>>() {
            @Override
            public void onResponse(Call<ResultDO<Revenue>> call, Response<ResultDO<Revenue>> response) {
                if (isFinish || response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    if (response.body().getResult() == null) {
                        return;
                    }
                    Revenue revenue=response.body().getResult();
                    price.setText(""+revenue.getAbleRevenue());
                }
            }
            @Override
            public void onFailure(Call<ResultDO<Revenue>> call, Throwable t) {
            }
        });

    }
}
